package com.koron.order.linepatrol.uav.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.core.util.StringUtils;
import com.koron.order.linepatrol.uav.bean.VO.LineDefectPatrolUnv;
import com.koron.order.linepatrol.uav.bean.query.LineDefectPatrolUnvQuery;
import com.koron.order.linepatrol.uav.service.LineUnvDefectPatrolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: LineDefectPatrolController
 * @Description:
 * @Date: 2023/2/9
 * @Author: 李一辰
 * @Version: 1.0
 **/

@Slf4j
@RestController
@RequestMapping("/lineDefectPatrolController")
@Api(tags = "无人机缺陷报告")
public class LineUnvDefectPatrolController {
    @Autowired
    private LineUnvDefectPatrolService lineUnvDefectPatrolService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @GetMapping("/list")
    @ApiOperation("列表查询(分页)")
    public Response<PageInfo<LineDefectPatrolUnv>> list(LineDefectPatrolUnvQuery lineDefectPatrolUnvQuery, PageQuery pageQuery){
        PageInfo<LineDefectPatrolUnv> list = ADOConnection.runTask(getCurrDs(), lineUnvDefectPatrolService, "list", PageInfo.class, lineDefectPatrolUnvQuery, pageQuery);
        if(StringUtils.isNotEmpty(lineDefectPatrolUnvQuery.getReportStatus())){
            List<LineDefectPatrolUnv> collect = list.getList().stream().filter(i -> lineDefectPatrolUnvQuery.getReportStatus().equals(i.getReportStatus())).collect(Collectors.toList());
            return Response.ok(new PageInfo<LineDefectPatrolUnv>(collect));
        }
        return Response.ok(list);
    }

    @PostMapping("/update")
    @ApiOperation("修改信息")
    public Response<LineDefectPatrolUnvQuery> update( LineDefectPatrolUnvQuery patrolUnvQuery) {
        Boolean patrolUnv = ADOConnection.runTask(getCurrDs(), lineUnvDefectPatrolService, "update", Boolean.class, patrolUnvQuery);
        return Response.ok(patrolUnvQuery);
    }
    @PostMapping("/deleteLogic")
    @ApiOperation("逻辑删除")
    public Response<Boolean> deleteLogic( String id) {
        Boolean isDelete = ADOConnection.runTask(getCurrDs(), lineUnvDefectPatrolService, "deleteLogic", Boolean.class, id);
        return  Response.ok(isDelete);
    }
    @PostMapping("/insert")
    @ApiOperation("新增")
    public Response<LineDefectPatrolUnvQuery> insert( LineDefectPatrolUnvQuery lineDefectPatrolUnv) {
        Boolean patrolUnv = ADOConnection.runTask(getCurrDs(), lineUnvDefectPatrolService, "insert", Boolean.class, lineDefectPatrolUnv);
        return Response.ok(lineDefectPatrolUnv);
    }
}
